package wshandlers

import (
	"encoding/json"
	"fmt"
	"statuspage/dockerinfo"
	"time"

	"golang.org/x/net/websocket"
)

func WsDockerInfo(ws *websocket.Conn) {
	for {
		data := dockerinfo.GetDockerList()
		msg, err := json.Marshal(data.ContainerInfo)
		if err != nil {
			fmt.Println(err)
			return
		}

		if err := websocket.JSON.Send(ws, string(msg)); err != nil {
			fmt.Println("Can't send")
			fmt.Println(err)
			break
		}
		time.Sleep(4 * time.Second)
	}
}
